from django.db import models
from django.contrib.auth.models import User
from project.settings import MEDIA_ROOT
# variables for this models file
wordLen=15
titleLen=30
paragraphLen=150

CHARACTER = 1
OX = 2
WAGON = 3

CHARACTER_WEIGHT = 0
OX_WEIGHT = 0
WAGON_WEIGHT = 3500
# Start class definitons 

# not talked about
class RandomEvent(models.Model):
    name = models.CharField(max_length=wordLen)
    probability = models.DecimalField(max_digits=5,decimal_places=4)
    def __unicode__(self):
        return self.name
    class Meta:
        abstract = True
    
        
class OptionHolder(models.Model):
    pass
        
class ItemHolder(models.Model):
    pass
   
class Ailment(RandomEvent):
    message = models.CharField(max_length=paragraphLen)
    minHealth = models.IntegerField()
    maxHealth = models.IntegerField()
    def __unicode__(self):
        return "Ailment:" + self.message
    
class Profession(OptionHolder):
    name = models.CharField(max_length=wordLen)
    description = models.CharField(max_length=paragraphLen)
    startingMoney = models.DecimalField(max_digits=8,decimal_places=2)
    def __unicode__(self):
        return self.name

class Party(ItemHolder):
    paceChoices = (
        (3,'Grueling'),
        (2,'Brisk'),
        (1,'Slow')
    )
    rationChoices = (
        (3,'Filling'),
        (2,'Normal'),
        (1,'Meager')
    )
    distanceFromStart = models.IntegerField()
    pace = models.IntegerField(choices=paceChoices)
    date = models.DateField(null=True)
    profession = models.ForeignKey(Profession)
    rations = models.IntegerField(choices=rationChoices)
    money = models.DecimalField(max_digits=8,decimal_places=2)
    game = models.ForeignKey('TravelGame')
    def __unicode__(self):
        return 'Party with profession of: ' + self.profession.name

class Member(models.Model):
    health = models.IntegerField()
    party = models.ForeignKey(Party)
    name = models.CharField(max_length=titleLen)
    status = models.ForeignKey(Ailment, blank=True, null=True)
    isMain = models.BooleanField()
    memberChoices = (
        (CHARACTER,'Traveler'),
        (OX,'Ox'),
        (WAGON,'Wagon')
    )
    weightChoices = (
        (CHARACTER_WEIGHT,'Character'),
        (OX_WEIGHT,'Ox'),
        (WAGON_WEIGHT,'Wagon')
    )
    carryWeight = models.IntegerField(choices=weightChoices)
    kind = models.IntegerField(choices=memberChoices,blank=False)
    def __unicode__(self):
        return self.name
    
class AbstractItem(models.Model):
    name = models.CharField(max_length=wordLen)
    description = models.CharField(max_length=paragraphLen)
    weight = models.DecimalField(max_digits=8,decimal_places=2)
    cost = models.DecimalField(max_digits=4,decimal_places=2)
    image = models.FileField(upload_to='images/oregon_trail/items/',null=True,blank=True)
    def __unicode__(self):
        return self.name
    
class Item(models.Model):
    itemType = models.ForeignKey(AbstractItem)
    quantity = models.IntegerField()
    holder = models.ForeignKey(ItemHolder,null=True,blank=True)
    def __unicode__(self):
        return self.itemType.name
    
class Option(models.Model):
    holder = models.ForeignKey(OptionHolder)
    name = models.CharField(max_length=wordLen)
    displayName= models.CharField(max_length=titleLen)
    value = models.TextField()
    def __unicode__(self):
        return self.displayName
    
class AbstractStore(ItemHolder):
    name = models.CharField(max_length=titleLen)
    location = models.ForeignKey('Landmark')
    def __unicode__(self):
        return 'Abstract: ' + self.name + ' at ' + self.location.name
    
class Store(ItemHolder):
    game = models.ForeignKey('OTG')
    templateStore = models.ForeignKey(AbstractStore)
    def __unicode__(self):
        return self.templateStore.name + ' at ' + self.templateStore.location.name + ' for ' + self.game.player.username + ' game number: ' + str(self.game.pk)

#class Map(models.Model):
#    #figure out map an landmark and travel game relationship
#    pass

class Landmark(OptionHolder):
    distanceFromStart = models.IntegerField()
    name = models.CharField(max_length = titleLen)
    image = models.FileField(upload_to='images/oregon_trail/landmarks/',null=True,blank=True)
    costModifier = models.DecimalField(decimal_places=1,max_digits=2,default=1); #prices goes up 10% per store, TODO:Implement costModifier
    def __unicode__(self):
        return self.name
    
# talk about later
class TravelGame(models.Model):
    player = models.ForeignKey(User)

# talk about later
class OTG(TravelGame):
    pass
    def __unicode__(self):
        return str(self.id) ###TODO figure out naming convention for instances 
    ##of other classes

        
class River(Landmark):
    minDepth = models.IntegerField()
    maxDepth = models.IntegerField()
    currentDepth = models.IntegerField(null=True,blank=True)
    ferry = models.BooleanField(default=False)
        
class FortTown(Landmark):
    pass
        
class NaturalWonder(Landmark):
    pass

class NormalLocation(Landmark): 
    pass
    
class Wagon(Member):
    brokenAxle = models.BooleanField(default=False)
    brokenWheel = models.BooleanField(default=False)
    def __unicode__(self):
        return "Wagon"



#class Robbery(randomEvent):
#    pass

#class InclementWeather(randomEvent):
#    pass

# Needs to be a def in a separate file?
#class REH(models.Model):
#    randomEvents = models.ForeignKey(randomEvent)
